import Application from "./Application.js";
import ServiceManager from "/System/Services/ServicesManager.js";
import Configuration from "/System/Configuration/Configuration.js";
import PluginManager from "/System/Plugin/PluginManager.js";
import ComponentService from "/System/Component/ComponentService.js";

export default class ApplicationBuilder {
    application = null;
    configuration = null;
    services = null;
    plugins = null;
    components = null;
    constructor(){
        this.application = new Application();
        this.configuration = new Configuration();
        this.services = new ServiceManager();
        this.plugins = new PluginManager();
        this.initialize();
    }

    initialize(){}

    setConfig(key, value) {
        this.configuration.set(key, value);
        return this;
    }

    addService(name, service) {
        this.services.register(name, service);
        return this;
    }

    build(){
        this.application.configuration = this.configuration;
        this.application.services = this.services;
        this.application.plugins = this.plugins;
        return this.application;
    }


    // 添加系统服务
    addComponentService(){
        this.services.register('Component', ComponentService, {singleton: true});
        this.application.component = this.services.resolve('Component');
        return this;
    }
}
